package org.fanrui.hrm.config;

import io.minio.MinioClient;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * minio配置
 *
 * @author fanrui
 */
@Getter
@Configuration
//读取yml中的配置到一个对象中
@ConfigurationProperties(prefix = "minio")
public class MinIoClientConfig {
    @Value("${minio.server}")
    private String server;
    @Value("${minio.port}")
    private int port;
    @Value("${minio.endpoint}")
    private String endpoint;
    @Value("${minio.access-key}")
    private String accessKey;
    @Value("${minio.secret-key}")
    private String secretKey;
    @Value("${minio.bucket}")
    private String bucket;

    /**
     * 创建minio连接对象
     *
     * @return minio连接对象
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder().endpoint(server, port, false).credentials(accessKey, secretKey).build();
    }

    public void setServer(String server) {
        this.server = server;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public void setBucket(String bucket) {
        this.bucket = bucket;
    }
}
